package com.intellagric.controller.module.trace_supplier;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.traceability.SupplierVo;
import com.intellagric.pojo.TraceSupplier;
import com.intellagric.service.traceability.trace_supplier.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/7
 * @DESC： 公司信息管理
 */
@Controller
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 添加公司信息
     * @Param 
     * @return ResponseMessage
     */
    @RequestMapping("/supplier/add")
    @ResponseBody
    public ResponseMessage add(TraceSupplier supplier) {
        //初始化数据
        supplier.setId(UUID.randomUUID().toString().replaceAll("-",""));
        supplier.setCreateDate(new Date());
        supplier.setUpdateDate(new Date());
        return supplierService.addSupplier(supplier);
    }

    /**
     * 删除公司信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/supplier/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return supplierService.deleteSupplier(id);
    }

    /**
     * 修改公司信息
     * @Param supplier
     * @return ResponseMessage
     */
    @RequestMapping("/supplier/edit")
    @ResponseBody
    public ResponseMessage edit(TraceSupplier supplier) {
        supplier.setUpdateDate(new Date());
        return supplierService.editSupplier(supplier);
    }

    /**
     * 查询公司信息
     * @return TraceSupplier
     */
    @RequestMapping("/supplier/{id}")
    @ResponseBody
    public TraceSupplier get(@PathVariable String id) {
        return supplierService.getSupplierById(id);
    }

    /**
     * 查询公司信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/supplier/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return supplierService.getSupplierList();
    }

    /**
     * 分页查询公司信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/supplier/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page ,int limit) {
        return supplierService.getSupplierPage(page,limit);
    }

    /**
     * 根据Vo类型分页查询公司信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/supplier/query")
    @ResponseBody
    public LayuiDataGridResult getPage(int page ,int limit,String keywork) {
        return supplierService.getSupplierByVo(page,limit,keywork);
    }

}
